﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Shpm.App.Commons.Db.Beans.Master;
using Shpm.App.Master.Dao;

public partial class App_Commons_PhysicalPopForm : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            GridView1.DataSourceID = null;
            SetCmbSex();
            ViewState["tID"] = (string)Request.QueryString["tID"];
        }
    }
    protected void btnSeach_Click(object sender, EventArgs e)
    {
        GridView1.DataSourceID = null;
        if (ComValidator1.DoValidator())
        {
            GridView1.DataSourceID = this.ObjectDataSource1.ID;
        }
    }
    //设置性别
    private void SetCmbSex()
    {
        CommonDictionaryBean paramBean = new CommonDictionaryBean();
        paramBean.Catalog = "SEX";
        CommonDictionaryDao dao = new CommonDictionaryDao();
        IList dataList = dao.FindByCatalog(paramBean);
        cmbSex.DataSource = dataList;
        cmbSex.DataBind();
        if (SetCmbIndex(dataList) != -1)
            cmbSex.SelectedIndex = SetCmbIndex(dataList);
    }

    //设置下拉框的默认值
    private int SetCmbIndex(IList list)
    {
        CommonDictionaryBean dataBean = new CommonDictionaryBean();
        for (int i = 0; i < list.Count; i++)
        {
            dataBean = (CommonDictionaryBean)list[i];
            if (dataBean.Default == true) return i;
        }
        return -1;
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow && e.Row.Cells[3].Text != string.Empty && e.Row.Cells[3].Text != null)
        {
             
            e.Row.Cells[3].Text = GetDocData("SEX", e.Row.Cells[3].Text);
        }
    }

    #region 取得数据字典的内容
    //取得数据字典的内容
    private string GetDocData(string str1, string str2)
    {
        CommonDictionaryBean dataBean = new CommonDictionaryBean();
        CommonDictionaryDao Dao = new CommonDictionaryDao();
        dataBean.Catalog = str1;
        dataBean.DictNo = str2;
        dataBean = Dao.Load(dataBean);
        if (dataBean != null && dataBean.Content != null) return dataBean.Content;
        else return string.Empty;
    }
    #endregion
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        GridViewRow row = GridView1.SelectedRow;
        string TxtVal = row.Cells[1].Text;
        Response.Write("<script language=JavaScript> window.opener.settext('" + (string)ViewState["tID"] + "','" + TxtVal + "');</script>");
        Response.Write("<script language=JavaScript> window.close();</script>");
    }
}
